<?php

namespace Business\Controller;

use Business\Controller\BaseController;

class PublicController extends BaseController {

    public function _initialize() {
        
    }

    //用户登录
    public function login() {
        $strPhone = I("business_phone");
        $strPassword = I("password");
        $where = [];
        empty($strPhone) && $this->error("请输入手机号");
        empty($strPassword) && $this->error("请输入密码");

        $where['business_phone'] = $strPhone;
        $where['password'] = md5($strPassword);
        $info = M('seller')->where($where)->find();
        if (empty($info)) {
            $this->error("账号或密码错误");
        }
//        if($info['state'] == 2){
//            $this->error("该账号被禁用");
//        }
//        
//        if ($info) {
//            if (md5($info['password']) == $strPassword) {
//                $this->error('账号或密码错误');
//            }
//            $this->success("登录成功", $info);
//        }
//        $data = $where;
//        $data['nickname'] = $strPhone;
//        $data['create_time'] = date("Y-m-d H:i:s");
//        $wid = M('seller')->add($data);
//        $info = M('seller')->where(['wid' => $wid])->find();
        $this->success("登录成功", $info);
    }

    public function regifururebusins() {
        $strPhone = I("business_phone");
        $strPassword = I("password");
        empty($strPhone) && $this->error("请输入手机号");
        $this->_authSign($strPhone);

        empty($strPassword) && $this->error("请输入密码");
        $where = [];
        $where['business_phone'] = $strPhone;
        $info = M('seller')->where($where)->find();
        if (!empty($info)) {
            $this->error("用户已存在");
        }

        $data = $where;
        $data['password'] = md5($strPassword);
        $data['nickname'] = $strPhone;
        $data['state'] = 2;
        $data['create_time'] = date("Y-m-d H:i:s");
        $data['isonwork'] = 0;
        $wid = M('seller')->add($data);
        $info = M('seller')->where(['wid' => $wid])->find();

        $this->success("注册成功", $info);
    }

    public function phoneUsersList() {
        $user_phones = I('user_phones');
        empty($user_phones) && $this->error('user_phones参数必须');
        $list = M('user')->field('user_id,user_phone,nickname,headpic,create_time,state')->where(['user_phone' => array('in', $user_phones)])->select();
        $this->returnList($list);
    }

}
